﻿using HandyControl.Controls;
using Prism.Commands;
using Prism.Mvvm;
using System.Linq;
using System.Windows;
using wms_wpf.Apiservice;
using wms_wpf.InPut;

namespace wms_wpf.DialogViewModel
{
    public class Dialog2ViewModel : BindableBase
    {



        public Dialog2ViewModel(IBaseService service)
        {
            ConfirmCommand = new DelegateCommand(Confirm);
            Service = service;
            InPut_BaseService = new InPut_BaseService();
        }

        public IBaseService Service;
        public DelegateCommand ConfirmCommand {  get; set; }
        private InPut_BaseService inPut_BaseService;
        public InPut_BaseService InPut_BaseService
        {
            get { return inPut_BaseService; }
            set { inPut_BaseService = value;RaisePropertyChanged();}
        }
        private bool isrunning;
        public bool Isruning
        {
            get { return isrunning; }
            set { isrunning = value; RaisePropertyChanged(); }
        }

        private Visibility visibility = Visibility.Hidden;

        public Visibility Visibility
        {
            get { return visibility; }
            set { visibility = value; RaisePropertyChanged(); }
        }


        private async void Confirm()
        {
            bool res = InPut_BaseService.GetType().GetProperties().All(property => property.GetValue(InPut_BaseService) != null);
            if (!res)
            {
                Growl.Info("数据不完整！", "msg");
                return;
            }
            Isruning = true;
            Visibility = Visibility.Visible;
            await Service.Create_Boxs(InPut_BaseService);
            Visibility = Visibility.Hidden;
            Isruning = false;
        }
    }
}
